package Priority_queue;

import java.util.PriorityQueue;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-03-06
 * Time:18:24
 * Text：703. 数据流中的第 K 大元素
 */
public class Text1 {
    PriorityQueue<Integer> heap;
    int _k;
    public void KthLargest(int k, int[] nums) {
        _k=k;
        heap=new PriorityQueue<>();
        for(int x:nums){
            heap.offer(x);
            if(heap.size()>_k)
            {
                heap.poll();
            }
        }
    }

    public int add(int val) {
        heap.offer(val);
        if(heap.size()>_k);
        {
            heap.poll();
        }
        return heap.peek();
    }
}
